package com.bw.medical.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.medical.entity.DepartmentEntity;
import com.bw.medical.service.DepartmentService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 科室表 
 *
 * @author wj
 * @email sunlightcs@gmail.com
 * @date 2021-08-22 21:39:10
 */
@RestController
@RequestMapping("medical/tbdepartment")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * 列表
     */
    @RequestMapping("/lists")
    public R list(@RequestParam Map<String, Object> params){
        IPage<DepartmentEntity> page=departmentService.getList(params);
        PageUtils pageUtils = new PageUtils(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getPages());
        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{departmentId}")
    public R info(@PathVariable("departmentId") Integer departmentId){
		DepartmentEntity department = departmentService.getById(departmentId);

        return R.ok().put("department", department);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DepartmentEntity department){
		departmentService.save(department);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DepartmentEntity department){
		departmentService.updateById(department);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] departmentIds){
		departmentService.removeByIds(Arrays.asList(departmentIds));

        return R.ok();
    }

}
